using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace SDK.Scripts.Module
{
	public class ModuleManager
	{
		private List<IModule> _moduleList = new List<IModule>();

		public ModuleManager()
		{
			IEnumerable<Type> enumerable = AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => from t in a.GetTypes()
				where Enumerable.Contains(t.GetInterfaces(), typeof(IModule))
				select t);
			foreach (Type item2 in enumerable)
			{
				if (item2.IsClass)
				{
					IModule item = Activator.CreateInstance(item2) as IModule;
					_moduleList.Add(item);
				}
			}
		}

		public T Module<T>()
		{
			foreach (IModule module in _moduleList)
			{
				if (typeof(T) == module.GetType())
				{
					return (T)module;
				}
			}
			return default(T);
		}
	}
}
